|
|
![]() | |
|
|
|
To access the contents, click the chapter and section titles.
Complete Idiot's Guide to Linux
Creating Links: lnLinks are created using the ln command. ln is used to create both soft and hard links. The syntax for the command is
ln [options] source destination
To create a symbolic (soft) link, you specify the -s option, which stands for symbolic. Heres an example for listing a directory:
[alberto@digital alberto]$ ls -l
total 2
drwxrwxr-x 3 alberto alberto 1024 Aug 1 20:41 adir/
-rw-rw-r-- 1 alberto alberto 57 Aug 2 13:12 file
Heres an example for creating a hard link:
[alberto@digital alberto]$ ln file file2
Heres one for creating a soft link:
[alberto@digital alberto]$ ln -s file file3
Here is the syntax for listing directory again. Notice that file3 points to file:
[alberto@digital alberto]$ ls -l
total 3
drwxrwxr-x 3 alberto alberto 1024 Aug 1 20:41 adir/
-rw-rw-r-- 2 alberto alberto 57 Aug 2 13:12 file
-rw-rw-r-- 2 alberto alberto 57 Aug 2 13:12 file2
lrwxrwxrwx 1 alberto alberto 4 Aug 2 13:15 file3 -> file
Here is the syntax for deleting the original file:
[alberto@digital alberto]$ rm file
Here is the syntax for listing again. Notice that file3 now points to a file that doesnt exist!
[alberto@digital alberto]$ ls -l
total 2
drwxrwxr-x 3 alberto alberto 1024 Aug 1 20:41 adir/
-rw-rw-r-- 1 alberto alberto 57 Aug 2 13:12 file2
lrwxrwxrwx 1 alberto alberto 4 Aug 2 13:15 file3 -> file
Links are used often in Linux to allow files to be placed in many directories at once. For example, the directory /usr/X11R6 contains files used by X Windows. Some older X Windows programs install into /usr/X11R5 or /usr/X11R4 instead. Through a series of symbolic links, Linux can make files from all three directories appear in a more general X Windows directory, /usr/X11, for easy access. This type of organizing is one of the primary uses for symbolic links. Reading FilesBeing able to move and organize files is an important skill. In the end, computers are primarily for storing and retrieving information. Here are a few commands that you can use for reading files when on a terminal:
Concatenating: catThe cat command reads one or more files and prints the result to the screen. (It concatenates all files to the screen.) cat is a generic command, and it is used very frequently when chaining multiple commands together. When we explore redirection in Chapter 14, Putting the Shell to Work, Ill show you how the cat is really used. The basic syntax of cat is
cat [options] files
Heres an example of using cat to view the /etc/passwd file (this is the file where information about users is kept):
[alberto@digital alberto]$ cat /etc/passwd
root:UGQDnB4s/nDAk:0:0:root:/root:/bin/bash
bin:*:1:1:bin:/bin:
daemon:*:2:2:daemon:/sbin:
adm:*:3:4:adm:/var/adm:
lp:*:4:7:lp:/var/spool/lpd:
sync:*:5:0:sync:/sbin:/bin/sync
shutdown:*:6:0:shutdown:/sbin:/sbin/shutdown
halt:*:7:0:halt:/sbin:/sbin/halt
mail:*:8:12:mail:/var/spool/mail:
news:*:9:13:news:/var/spool/news:
uucp:*:10:14:uucp:/var/spool/uucp:
operator:*:11:0:operator:/root:
games:*:12:100:games:/usr/games:
gopher:*:13:30:gopher:/usr/lib/gopher-data:
ftp:*:14:50:FTP User:/home/ftp:
nobody:*:99:99:Nobody:/:
postgres:!:100:101:PostreSQL Server:/var/lib/pgsql:/bin/bash
alberto:YMMhuMSru1hME:501:501:AlbertoRicart:/home/alberto:/bin/bash
As you can see, cat opened the file /etc/passwd and printed every line to the console. The cat command offers several options; the most useful are listed in Table 12.1.
|
|||||||||||||||||||||||||
|
Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement. |